package com.bc.bcbuyerapihttp.controller;

import com.bc.bcapi.dao.T_User_buyer_infoMapper;
import com.bc.bcapi.service.T_ProjectService;
import com.bc.bcapi.service.T_Project_tagService;
import com.bc.bcbuyerapihttp.common.UserContext;
import com.bc.bcmodel.BuyerUserInfo;
import com.bc.bcmodel.domain.T_Project_tagModel;
import com.bc.bcmodel.domain.T_User_buyer_infoModel;
import com.bc.bcmodel.domain.T_User_seller_infoModel;
import com.bc.bcmodel.req.*;
import com.bc.bcmodel.resp.ProjectSearchParamResp;
import com.bc.bcmodel.resp.ProjectSearchStatusParamResp;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Name ProjectController
 * @Description
 * @Author douhaichao
 * @Date 2018/8/23 14:25
 * @Version 1.0
 **/
@RestController
@Api("项目管理")
@RequestMapping(value = "project")
public class ProjectController {

    @Autowired
    T_ProjectService t_projectService;

    @Autowired
    T_Project_tagService t_project_tagService;

    @ApiOperation("获取搜索参数")
    @RequestMapping(value = "getsearchparam", method = RequestMethod.GET)
    public JsonResult getSearchParam(HttpServletRequest request) {
        return t_projectService.getSearchParam(request);
    }

    @ApiOperation("获取项目列表")
    @RequestMapping(value = "search", method = RequestMethod.POST)
    public JsonResult search(@RequestBody ProjectSearchParamReq req,
                             HttpServletRequest request, HttpServletResponse response) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_projectService.search(req, request, response);
    }

    @ApiOperation("项目详情")
    @RequestMapping(value = "detail", method = {RequestMethod.POST, RequestMethod.GET})
    public JsonResult detail(@RequestBody ProjectDetailReq req, HttpServletRequest request, HttpServletResponse response) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_projectService.detail(req, request, response);
    }

    @ApiOperation("我的ICO+我的提醒{type_id 1 加入购物车 2 我收藏的ico 3 我的提醒 ;pstatus 1进行中，2即将开始，3已结束}")
    @RequestMapping(value = "getmyico", method = RequestMethod.POST)
    public JsonResult getMyIco(@RequestBody MyIcoReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_projectService.getMyIco(req);
    }

    @ApiOperation("设置(我的收藏+加入购物车+我的提醒)，typeid:{1 加入购物车 2 我收藏的ico 3 我的提醒}")
    @RequestMapping(value = "setmyico", method = RequestMethod.POST)
    public JsonResult setMyIco(@RequestBody ProjectSetIcoReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_projectService.setMyIco(req);
    }

    @ApiOperation("我参与的项目{typeid:1 我打标的ICO 2我参标的ICO 3我业务分析的ICO 4我代码分析的ICO}")
    @RequestMapping(value = "getmyjoin", method = RequestMethod.POST)
    public JsonResult getMyJoin(@RequestBody ProjectMyJoinReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_projectService.getMyJoin(req);
    }

    @ApiOperation("查询用户的声音")
    @RequestMapping(value = "gettag", method = RequestMethod.POST)
    public JsonResult getTag(@RequestBody ProjectTagReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo != null) {
            req.setUser_id(userInfo.getUser_id());
        }
        return t_project_tagService.getTag(req);
    }

    @ApiOperation("添加用户的声音")
    @RequestMapping(value = "settag", method = RequestMethod.POST)
    public JsonResult setTag(@RequestBody T_Project_tagModel req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_project_tagService.setTag(req);
    }

    @ApiOperation("支持某个用户的声音")
    @RequestMapping(value = "goodtag", method = RequestMethod.POST)
    public JsonResult goodTag(@RequestBody T_Project_tagModel req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_project_tagService.goodTag(req);
    }

    @ApiOperation("获取项目类型")
    @RequestMapping(value = "getprojecttype", method = RequestMethod.GET)
    public JsonResult getProjectType() {
        return t_projectService.getProjectType();
    }

}
